﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KPIS.GERP.GBMS.BLL;
using KPIS.GERP.GBMS.APP_UI.Common;

namespace KPIS.GERP.GBMS.APP_UI.Form
{
    public partial class BGM_Project_Pass : System.Web.UI.Page
    {
        Main main = new Main();
        ComboBLL combo = new ComboBLL();
        RequestPass requestPass = new RequestPass();
        ProjectPass projectPass = new ProjectPass();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadJobSiteSeq();
            }
        }

        protected void LoadJobSiteSeq()
        {
            ddlJobSiteSeq.DataSource = combo.ListJobsite();
            ddlJobSiteSeq.DataBind();

            main.InsertEmptyDDLSelect(ddlJobSiteSeq);
            ddlJobSiteSeq.SelectedIndex = 0;
        }

        protected void ClosePopup()
        {
            ScriptManager.RegisterClientScriptBlock(
                this.Page,
                this.GetType(),
                "WebUserControlSript",
                "returnToParent()",
                true);
        }

        protected void btnPopupSave_Click(object sender, EventArgs e)
        {
            string type = Request.QueryString["type"].ToString();
            string strProjectID = Session["ProjectID"].ToString();
            string strJobSiteSeq = ddlJobSiteSeq.SelectedValue;

            if (strJobSiteSeq.Length == 0)
            {
                main.MessageAlert(Page, "กรุณาเลือก [หน่วยงานเพื่อทราบ]");
                return;
            }

            switch (type)
            {
                case "rq" :
                    requestPass.Insert(strProjectID, strJobSiteSeq, new SsMng().GetUss(SsMng.SsUserType.EmpSeq));
                    break;
                case "pj" :
                    projectPass.Insert(strProjectID, strJobSiteSeq, new SsMng().GetUss(SsMng.SsUserType.EmpSeq));
                    break;
            }

            ClosePopup();
        }
    }
}